extends CharacterBody2D

@export var stats: PandoraEntity
@onready var raffle = preload("res://data/dialogue/稻草人.dialogue")
@onready var animation_player: AnimationPlayer = %AnimationPlayer
@onready var tip: Sprite2D = %tip
@onready var sprite: AnimatedSprite2D = %sprite
@onready var state_chart: StateChart = %StateChart

const BALLOON_OFFSET := Vector2(0, -50)   # 气泡w相对物体的朝上偏移量
var dialogue

func _ready() -> void:
	sprite.play("idle")

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("interact") and tip.visible == true and dialogue == null:
		get_viewport().set_input_as_handled()
		dialogue = DialogueManager.show_dialogue_balloon(raffle, "start")
		await dialogue.ready
		dialogue.balloon.position = get_global_transform_with_canvas() * BALLOON_OFFSET
		get_tree().paused = true
		
func _on_area_2d_area_entered(_area: Area2D) -> void:
	animation_player.play("!move")

func _on_area_2d_area_exited(_area: Area2D) -> void:
	animation_player.stop()
	tip.visible = false

func get_stats():
	return stats

	
